package com.burgeon.backend.Rest.Tags;
/**
 * 通过组名查询子标签
 */


import com.burgeon.backend.Rest.base.RESTBase;
import org.json.JSONArray;
import org.springframework.util.MultiValueMap;

import java.util.ArrayList;
import java.util.HashMap;

public class FindTagsItem extends RESTBase {

    private String ip;
    private String account;
    private String password;

    public FindTagsItem(String ip, String account, String password) {
        this.ip = ip;
        this.account = account;
        this.password = password;
    }

    /**
     * 发送并接收字符创
     */

    public ArrayList<String> getData(String code) throws Exception {
        String url = "http://" + ip + "/servlets/binserv/Rest";

        String str = RESULT(Data(code), url);
        System.err.println(str);
        String rows = new JSONArray(str).getJSONObject(0).getString("code");

        if (!"0".equals(rows)) {
            throw new Exception("获取数据错误");
        }
        ArrayList<String> data = new ArrayList<>();
        JSONArray jsonArray = new JSONArray(str).getJSONObject(0).getJSONArray("rows");
        for (int i=0;i<jsonArray.length();i++){
            data.add(jsonArray.getJSONArray(i).getString(0));
        }
        System.err.println(data);
        return data;
    }

    private MultiValueMap Data(String code) {
        HashMap params = new HashMap();
        ArrayList columns = new ArrayList();//查询字段

        columns.add("NAME");

        params.put("columns", columns);
        params.put("table", "C_VIPATTRIBVALUE");//表名

        params.put("count", "true");

        HashMap paramss = new HashMap();
        String ac = "'=" + code + "'";
        paramss.put("column", "'C_VIPATTRIBDEF_ID;NAME'");
        paramss.put("condition", ac);
        params.put("params", paramss);

        return DATA("Query", params, account, password);
    }

    public static void main(String[] args) {
        FindTagsItem g = new FindTagsItem("59.110.28.94:90", "nea@burgeon.com.cn", "burgeon55321");
        try {
            System.err.println(g.getData("价格"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
